package com.xu.chuang.show.service.impl;

import com.google.gson.Gson;
import com.xu.chuang.show.bean.ShowUser;
import com.xu.chuang.show.network.HttpUtil;
import com.xu.chuang.show.network.Json2T;
import com.xu.chuang.show.service.inte.UserReqService;
import com.xu.chuang.show.util.Config;
import com.xu.chuang.show.util.JoiningURL;

/**
 * Created by coder on 2016/8/7.
 * @author MagicRain
 */
public class UserReqImpl implements UserReqService{

    @Override
    public ShowUser register(ShowUser showUser) {
        String path = Config.baseURL + Config.registerURL;
        Gson gson  = new Gson();
        HttpUtil.post(path, gson.toJson(showUser));
        return null;
    }

    @Override
    public ShowUser login(String email, String password) {
        String path = Config.baseURL + Config.loginURL;
        String pathAndParam = JoiningURL.addURLParam(path, "email", email);
        String pathAndParamAndParam =
                JoiningURL.addNextParam(pathAndParam,"password", password);
        String dateString = HttpUtil.get(pathAndParamAndParam);
        return Json2T.getOb(dateString, ShowUser.class);
    }

    @Override
    public ShowUser modify(ShowUser showUser) {
        String path = Config.baseURL + Config.modifyUser;
        Gson gson  = new Gson();
        HttpUtil.post(path, gson.toJson(showUser));
        String pathFind = Config.baseURL +Config.showUserFindOne;
        String pathAndParam = JoiningURL.addURLParam(pathFind, "showUserId",
                showUser.getShowUserId().toString());
        String dataString = HttpUtil.get(pathAndParam);
        return Json2T.getOb(dataString, ShowUser.class);
    }

    @Override
    public ShowUser checkedRepeat(String email) {
        String path = Config.baseURL + Config.checkedRepeat;
        String pathAndParam = JoiningURL.addURLParam(path, "email", email);
        String dataString = HttpUtil.get(pathAndParam);
        return Json2T.getOb(dataString, ShowUser.class);
    }
}
